class TeacherSearcheService {
    
    boolean transactional = false
    static scope = "session"
    def authenticateService

    def searchTimes = 0
    def name=""
    def sex=""
    def role=""
    def staff=""
    def degree=""
    def features=""
    def school

    def searcheTeacherInit(searchName,searchSex,searchRole,searchstaff,searchDegree,searchFeatures,searchSchool) {
        name = searchName
        sex = searchSex
        role = searchRole
        staff = searchstaff
        degree = searchDegree
        features = searchFeatures
        school = searchSchool
        searchTimes++
    }

    def getSearchTeacherName() {
        return name
    }

    def searchTeacherList() {
        def c = Teacher.createCriteria()
        def results = c {
            if(name){
                 like ("name", "%"+name+"%")
            }
            if(staff){
                 like("staff", staff)
            }
            if(degree){
                 like("degree", degree)
            }
            if(features){
                 like("features", features)
            }
            if(sex){
                 like("sex", sex)
            }
            eq ("school" , school)
            //eq ("state" , false)
            //eq ("enabled" , true)
        }
        if(role && results.size() > 0){
            results = results.grep{
                it.authorities.any{el ->
                    el.authority?.trim() == role?.trim()
                }
            }
        }
        log.info(results.size())
        def teacherstaff = org.grails.plugins.lookups.Lookup.codeList("teacherstaff")
        def teacherdegree = org.grails.plugins.lookups.Lookup.codeList("teacherdegree")
        def teacherfeatures = org.grails.plugins.lookups.Lookup.codeList("teacherfeatures")

        List roles = Role.list()
        def adminRole = authenticateService.securityConfig.security.adminRole
        def schoolMasterRole = authenticateService.securityConfig.security.schoolMasterRole
        def grepRoles = roles.grep{
            it.authority != adminRole && it.authority != schoolMasterRole
        }
        [teacherInstanceList: results,
        teacherstaff:teacherstaff,
        teacherdegree:teacherdegree,
        teacherfeatures:teacherfeatures,
        roles:grepRoles,
        role:role,
        staff:staff,
        degree:degree,
        features:features,
        sex:sex]
    
    }
}
